home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 012 / reprate.arc / REPRATE.ASM next >
Encoding:
Assembly Source File  |  1984-12-08  |  7.9 KB  |  228 lines

  1. title Reprate
  2. page 60,132
  3. ;
  4. ;
  5. ; This program will set the TYPEMATIC rate of the PC AT keyboard.
  6. ; Since the rate change is done in the keyboard, Basic does not
  7. ; change repetition rate, also you can call this from Basic by
  8. ; using the SHELL"REPTATE X" command, X being the rate.
  9. ;
  10. ; If you have any problems and or suggestions, please contact
  11. ; me :
  12. ; Ralph Blanco
  13. ; 4201 Montibello Drv
  14. ; Charlotte, NC, 28226
  15. ; (704)542-1118
  16. ;
  17. ;
  18. code    segment
  19.         assume cs:code, ss:code, es:code, ds:code
  20.  
  21.         keystat equ     0097h
  22. ;
  23. ;
  24.         org     0100h
  25. ;
  26.         reprate   proc    near
  27. ;
  28. ;  Get machine id
  29. ;  PC = FF
  30. ;  XT = FE
  31. ;  FD = jr
  32. ;  FC = AT
  33. ;
  34.     push    ds        ; set return segment address to stack
  35.     sub    ax,ax        ; clear a reg
  36.     push    ax        ; put zero return address to stack
  37. ;    
  38.         push    es
  39.         mov     ax,0ffffh       ; segment of machine id byte
  40.         mov     es,ax
  41.         mov     al,es:[0eh]     ; machine id byte at FFFF:0E
  42.         pop     es
  43.         cmp     al,0fch         ; FC = id byte for AT
  44.         jnz     exit1
  45. ;
  46. ;  Get value of X from command line
  47. ;
  48.         xor     ax,ax           ; clear ax
  49.         mov     di,0080h        ; address of command line
  50.         mov     al,[di]         ; numbrer of chars in command
  51.         cmp     al,0
  52.         jz      exit            ; nothing in command line
  53.         add     di,ax           ; point to last character
  54.         call    get_nibble      ; convert ascii to hex
  55.         jc      exit            ; carry flag set if invalid character
  56. ;
  57. ;  Send command and rate to keyboard controller
  58. ;
  59.         mov     ax,00f3h        ; set typematic rate command
  60.         call    snd_data        ; send it to keyboard 8042
  61.         lea     di,rate         ; get table address in di
  62.         mov     bh,0            ; clear upper nibble
  63.         mov     al,[di+bx]      ; get new value in al
  64.         call    snd_data        ; send it to keyboard 8042
  65. ;
  66.         ret                     ; all done, return to dos
  67. ;
  68. ;  Error messages
  69. ;
  70. exit:   lea     dx,msg1         ; get address of menu message
  71. out:    call    say
  72.         ret                     ; return to dos
  73. ;
  74. exit1:  lea     dx,msg2         ; get address of wrong machine message
  75.         jmp     out
  76. ;
  77. say:    mov     ah,09h          ; get display function
  78.         int     21h             ; let dos display message
  79.         ret
  80. ;
  81. ; This procedure came from the program
  82. ; Change File Attribute
  83. ; written by
  84. ; William J. Burlingame, 12/83
  85. ;
  86. ; Modified by
  87. ; Ralph Blanco, 12/84
  88. ;
  89. ;        convert ascii to hex
  90. ;        entry:
  91. ;                es:di = address of ascii character
  92. ;        exit:
  93. ;                bl = converted character
  94. ;                     carry flag set if error
  95. ;
  96. get_nibble      proc    near
  97.         mov     bl,[di]         ; get character
  98.         sub     bl,'0'          ; strip ascii bits
  99.         jl      err             ; not hex numeric
  100.         cmp     bl,9            ; is it numeric
  101.         jle     ok              ; yes
  102.         and     bl,05fh         ; change to upper case
  103.         cmp    bl,011h        ; check for valid alpha
  104.         jl    err        ; no, must be bad
  105.         sub     bl,7            ; must be a-f
  106.         cmp     bl,0fh          ; check if true
  107.         jg      err             ; guess not
  108.  
  109. ok:     clc                     ; ok indicator
  110.         ret
  111. err:    stc                     ; error indicator
  112.         ret
  113. get_nibble      endp
  114. ;
  115. ;
  116. ;  Send commands and data to keyboard controller (8042)
  117. ;  This procedure came from the AT Tech Ref manual, page
  118. ;  5-120. It resdides in ROM address F000:33C5 in my machine.
  119. ;
  120. snd_data        proc    near
  121.  
  122.         push    ax              ; save registers
  123.         push    bx
  124.         push    cx
  125.         push    ds
  126.         mov     bx,0040h        ; get a 0040h
  127.         mov     ds,bx           ; make the data segment 0040h
  128.         mov     bh,al           ; save byte for retries
  129.         mov     bl,03           ; load number of retries
  130. sd0:    cli                     ; disable interrupts
  131.         and     byte ptr ds:keystat,0cfh  ; clear ACK and Resend flags
  132.         sub     cx,cx
  133. sd5:    in      al,64h          ; read keyboard status port
  134.         test    al,02h          ; check for buffer full
  135.         loopnz  sd5             ; wait for buffer not full
  136.         mov     al,bh           ; get byte to send to 8042
  137.         out     60h,al          ; send it to 8042
  138.         sti                     ; you can interrupt me again
  139.         mov     cx,1a00h        ; load count for 10ms+
  140. sd1:    test    byte ptr ds:keystat,030h ; check for status
  141.         jnz     sd3             ; if bits set, then it got someting, ok
  142.         loop    sd1             ; if not, then wait a while
  143. sd2:    dec     bl              ; decrement retry count
  144.         jnz     sd0             ; lets do it again
  145.         or      byte ptr ds:keystat,080h  ; turn on error flag
  146.         stc                     ; set carry flag for my error
  147.         jmp     sd4             ; somebody unplugged the keyboard
  148. sd3:    test    byte ptr ds:keystat,010h ; check for an ACK
  149.         jz      sd2             ; if not, resend
  150.         clc                     ; clear my error flag
  151. sd4:    pop     ds              ; restore registers
  152.         pop     cx
  153.         pop     bx
  154.         pop     ax
  155.         ret                     ; return
  156. snd_data       endp
  157. ;
  158. ; Message area
  159. ;
  160. lf      equ     0ah
  161. cr      equ     0dh
  162. ;
  163. msg1    db      cr,lf,9,'USAGE: reprate X',lf
  164.         db      cr,lf,9,'This program changes the typematic'
  165.         db      cr,lf,9,'rate for the PC AT keyboard.',lf
  166.         db      cr,lf,9,'X = The repetition rate desired.'
  167.         db    cr,lf,9,'X = Valid hex character 0...F'
  168.         db      cr,lf,9,'Use one of the values in the table:',lf,lf
  169.         db      cr,lf,9,'X    CPS RATE       X    CPS RATE'
  170.         db      cr,lf,9,'---------------------------------'
  171.         db      cr,lf,9,'0  =  30            8  =  7.5'
  172.         db      cr,lf,9,'1  =  24            9  =  6.0'
  173.         db      cr,lf,9,'2  =  20            A  =  5.0'
  174.         db      cr,lf,9,'3  =  17            B  =  4.3'
  175.         db      cr,lf,9,'4  =  15            C  =  3.7'
  176.         db      cr,lf,9,'5  =  12            D  =  3.0'
  177.         db      cr,lf,9,'6  =  10 (Normal)   E  =  2.5'
  178.         db      cr,lf,9,'7  =  8.6           F  =  2.1'
  179.         db      cr,lf,lf,lf,'$'
  180. ;
  181. msg2    db      cr,lf,9,'This program works in the PC AT only.',cr,lf,lf,'$'
  182. ;
  183. ; Typematic rate table
  184. ; Sample normal 10 cps
  185. ;
  186. ;                 Bit position   7 6 5   4  3 2 1 0
  187. ;                 Hex value      8 4 2   1  8 4 2 1
  188. ;                         0 -----| | |   |  | | | |----- 0
  189. ;                         0 -------| |   |  | | |------- 0
  190. ;                         1 ---------|   |  | |--------- 1
  191. ;                       Delay            |  |----------- 1
  192. ;                                        |-------------- 0
  193. ;                                                 Repetition Rate
  194. ;
  195. ;                Delay + Repetition rate = HEX 2C
  196. ;
  197. ;                Delay = (((bits 6,5) +1 * 250 milliseconds)
  198. ;                Delay is the time from your first key press
  199. ;                to the first keyboard repeat.
  200. ;
  201. ;                Rate = 1 / (((8+(bits 2,1)) * (2^(bits 4,3)) * 0.00417)
  202. ;
  203. ;                For more information see AT Tech Ref, Keyboard page 4-7
  204. ;
  205. ;
  206. rate    db      20h     ; 30   cps
  207.         db      22h     ; 24   cps
  208.         db      24h     ; 20   cps
  209.         db      26h     ; 17.1 cps
  210.         db      28h     ; 15   cps
  211.         db      2ah     ; 12   cps
  212.         db      2ch     ; 10   cps (normal)
  213.         db      2eh     ; 8.6  cps
  214.         db      30h     ; 7.5  cps
  215.         db      32h     ; 6.0  cps
  216.         db      34h     ; 5.0  cps
  217.         db      36h     ; 4.3  cps
  218.         db      38h     ; 3.7  cps
  219.         db      3ah     ; 3.0  cps
  220.         db      3ch     ; 2.5  cps
  221.         db      3fh     ; 2.0  cps
  222. ;
  223. reprate   endp
  224. code    ends
  225.         end     reprate
  226. ;        end of program
  227.         end
  228.